package org.example;

import org.example.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
@EnableFeignClients
public class BusinessServiceApplication {

    @Autowired
    private BusinessService businessService ;

    public static void main(String[] args) {
        SpringApplication.run(BusinessServiceApplication.class ,args) ;
    }

    /**
     * 开始下单
     * @param userId
     * 用户的 Id
     * @param commodityCode
     * 商品的编号
     * @param orderCount
     * 商品的数量
     * @return
     */
    @GetMapping("/purchase/{userId}/{commodityCode}/{orderCount}")
    public ResponseEntity<Void> purchase(@PathVariable("userId") String userId, @PathVariable("commodityCode")String commodityCode, @PathVariable("orderCount")Integer orderCount){
        businessService.purchase(userId,commodityCode,orderCount);
        return ResponseEntity.ok().build();
    }
}
